public class Task02 {
    public static void main(String[] args) {

        String s1="asdafghjka";
        String s2="aaasdfg";
        String substring=null;
        String min=(s1.length()>s2.length())?s2:s1;
        String max=(s1.length()<s2.length())?s2:s1;

        out:for (int i = 0; i < min.length();i++) {

            for (int j = 0,k=min.length()-i; k!=min.length()+1 ; j++,k++) {

                substring = min.substring(j, k);
                if (max.contains(substring)){
                    System.out.println(substring);
                    break out;
                }
            }
        }


    }
}